﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="toimiku_dokumentVastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ToimikuDokumentVastus))]
    public class ToimikuDokumentVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IToimikuDokumentVastus clazz;
        
        public ToimikuDokumentVastusSerializer(IToimikuDokumentVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("viide_manusele");
            if (clazz.ViideManusele!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ViideManusele))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ViideManusele");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("failinimi");
            if (clazz.Failinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Failinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Failinimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("dokument");
            if (clazz.Dokument!=null) {
                global::Xtee.Core.SerializationMetadata metaDokument = this.GetMetaData(clazz.Dokument);
                Writer.WriteTypeAttribute(metaDokument.TypeQualifiedName.Namespace, metaDokument.TypeQualifiedName.Name);
                metaDokument.NewSerializer(clazz.Dokument).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Dokument");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="viide_manusele") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimiku_dokumentVastus>viide_manusele");
                }
                clazz.ViideManusele = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("viide_manusele")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>toimiku_dokumentVastus>viide_manusele", Reader.LocalName);
            }
            if (Reader.LocalName=="failinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimiku_dokumentVastus>failinimi");
                }
                clazz.Failinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("failinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>toimiku_dokumentVastus>failinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="dokument") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>toimiku_dokumentVastus>dokument");
                }
                global::Xtee.Core.SerializationMetadata metaDokument = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IToimikuDokumendidDokument>(Reader, "toimiku_dokumendid_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Dokument = metaDokument.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IToimikuDokumendidDokument>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("dokument");
                    metaDokument.NewSerializer(clazz.Dokument).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>toimiku_dokumentVastus>dokument", Reader.LocalName);
            }
        }
    }
}
